from Player import Player


class TextUI:
    def __init__(self, humenPlayer, machinePlayer):
        self.__humenPlayer = humenPlayer
        self.__machinePlayer = machinePlayer

    def showTitle(self, title):
        print('%s%s' % ('*' * 11 * 2, '*' * len(title) * 2))
        print('*%s%s%s*' % (' ' * 10, title, ' ' * 10))
        print('%s%s' % ('*' * 11 * 2, '*' * len(title) * 2))

    def showPlayerInfo(self, playerTitle):
        print(playerTitle)
        self.__showCardBoxInfo('%s卡牌'%self.__humenPlayer.name, self.__humenPlayer.cardBox)
        self.__showCardBoxInfo('%s卡牌'%self.__machinePlayer.name, self.__machinePlayer.cardBox)

    def __showCardBoxInfo(self, cardBoxTitle, cardBox):
        if cardBox.isEmpty():
            return

        print(cardBoxTitle + '：', end='')
        for i, card in enumerate(cardBox.cards):
            print('[%d-%s/%s]' % (i + 1, card.name, card.hp), end='')
        print()

    def showRoundInfo(self, roundTitle, roundIdx):
        print('--------------------第%d轮-%s--------------------' % (roundIdx, roundTitle))

    def showEndGame(self):
        if self.__machinePlayer.isEmptyByCardBox():
            self.showTitle('我方大获全胜！')
        else:
            self.showTitle('就差一点点，请再接再厉！')